package org.hhy.xxl.crud.dao;


import org.elasticsearch.action.delete.DeleteRequest;

import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.client.RestHighLevelClient;
import org.hhy.xxl.crud.annotation.es.EsEntity;
import org.hhy.xxl.job.executor.bean.BaseEntity;
import org.lht.boot.lang.util.ClassUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.NoRepositoryBean;

import java.io.IOException;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 *
 * @author LiuHao
 * @date 2020/9/13 23:03
 * @description ES CRUD 操作
*/
@NoRepositoryBean
public class ElasticSearchCurdDao<E extends BaseEntity<PK>, PK extends Serializable> implements BaseCrudDao<E,PK> {


    @Autowired(required = false)
    private RestHighLevelClient restClient;
    protected EsEntity esEntity;
    protected Integer searchMaxSize;
    private Class<E> entityType;
    private boolean refresh = false;


    @SuppressWarnings("unchecked")
    public ElasticSearchCurdDao(){
        this.entityType = (Class<E>) ClassUtil.getGenericType(this.getClass(),0);
        this.esEntity = ClassUtil.getAnnotation(this.entityType,EsEntity.class);
        this.searchMaxSize = 9999;
    }



    @Override
    public int delete(PK pk) {
        return 0;
    }

    @Override
    public void deleteById(Collection<PK> ids) {

    }

    @Override
    public <S extends E> void delete(Collection<S> entities) {

    }

    @Override
    public <S extends E> void delete(S entity) {

    }

    @Override
    public PK add(E e) {
        return null;
    }

    @Override
    public <S extends E> List<PK> add(Collection<S> entities) {
        return null;
    }

    @Override
    public E findOne(PK pk) {
        return null;
    }

    @Override
    public List<E> findAll(Collection<PK> ids) {
        return null;
    }

    @Override
    public List<E> findAll() {
        return null;
    }

    @Override
    public PK update(E e) {
        return null;
    }

    @Override
    public List<PK> update(Collection<E> entities) {
        return null;
    }

    @Override
    public PK upsert(E e) {
        return null;
    }

    @Override
    public List<PK> upsert(Collection<E> entities) {
        return null;
    }

    @Override
    public PK patch(E e) {
        return null;
    }

    @Override
    public List<PK> patch(Collection<E> entities) {
        return null;
    }

    /** ==== private function start ==== **/

    /**
     * 获取索引别名
     * @return
     */
    private String getAlias(){
        return this.esEntity.alias() == null ? this.esEntity.index() : this.esEntity.alias();
    }

    /**
     * 获取索引类型
     * @return
     */
    private String getType(){
        return this.esEntity.type();
    }

    /**
     * 获取索引
     * @return
     */
    private String getIndex(){
        return this.esEntity.index();
    }

    /**
     * 获取最大查询数
     * @return
     */
    private Integer getSearchMaxSize(){
        return this.searchMaxSize;
    }

    /**
     * 设置最大查询数
     * @param searchMaxSize
     */
    private void setSearchMaxSize(final Integer searchMaxSize){
        this.searchMaxSize = searchMaxSize;
    }

    /**
     * 设置是否刷新
     * @param refresh
     */
    private void setRefresh(final boolean refresh){
        this.refresh = refresh;
    }
}

